package com.dev.elasticsearch.demo;

import com.dev.elasticsearch.entity.Dictionary;
import com.dev.elasticsearch.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName : Demo  //类名
 * @Description :   //描述
 * @Author :   //作者
 */
@RestController
@RequestMapping("demo")
public class Demo {
    @Autowired
    private DictionaryService dictionaryService;

    @GetMapping("/list")
    private ResponseEntity list(Dictionary dictionary){
        Iterable<Dictionary> list = dictionaryService.list(dictionary);
        return ResponseEntity.ok(list);
    }

    @GetMapping("/count")
    private ResponseEntity count(){
        long count = dictionaryService.count();
        return ResponseEntity.ok(count);
    }

    @PostMapping("/save")
    private ResponseEntity save(Dictionary dictionary){
        Dictionary save = dictionaryService.save(dictionary);
        return ResponseEntity.ok(save);
    }

    @PutMapping("/update")
    private ResponseEntity update(Dictionary dictionary){
        Dictionary save = dictionaryService.updateById(dictionary);
        return ResponseEntity.ok(save);
    }

    @DeleteMapping("/remove")
    private ResponseEntity remove(Dictionary dictionary){
        dictionaryService.remove(dictionary);
        return ResponseEntity.ok(null);
    }

    @DeleteMapping("/remove/{id}")
    private ResponseEntity remove(@PathVariable("id") String id){
        dictionaryService.removeById(id);
        return ResponseEntity.ok(null);
    }

    @DeleteMapping("/removeAll")
    private ResponseEntity removeAll(){
        dictionaryService.removeAll();
        return ResponseEntity.ok(null);
    }
}
